package cn.kailangtu.dataspot.data;

import android.util.Log;

import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import cn.kailangtu.commontools.DateTimeUtils;
import cn.kailangtu.dataspot.db.ExceptionLogEntity;
import cn.kailangtu.dataspot.db.OptionLogEntity;
import cn.kailangtu.dataspot.db.SwitchLogEntity;


public class ExceptionData {
    private long logId;
    private long logTime;
    private String logContent;
    private String logTimeString;


    public ExceptionData(long logId,String logTimeString,String logContent){
        this.logId = logId;
        this.logTime = logTime;
        this.logContent = logContent;
        this.logTimeString = logTimeString;
    }

    public long getLogId() {
        return logId;
    }

    public void setLogId(long logId) {
        this.logId = logId;
    }

    public long getLogTime() {
        return logTime;
    }

    public void setLogTime(long logTime) {
        this.logTime = logTime;
    }

    public String getLogTimeString(){
        return logTimeString;
    }

    public String getLogContent() {
        return logContent;
    }

    public void setLogContent(String logContent) {
        this.logContent = logContent;
    }

    /***
     * 获取日志数据
     * @param pageIndex 要获取的页索引
     * @param logType 1，是错误日志，3是操作日志
     * @return
     */
    public static List<ExceptionData> getLogData(int pageIndex,int logType){

//        long[] ids = new long[14];
//        for(int i = 0;i< 14;i++){
//            ids[i]  =  pageIndex * 14 +(i+1);
//        }
        if(logType == 1)
        {
            return getErrLog(pageIndex);
        }
        else if(logType == 2)
        {
            return getSwitchLog(pageIndex);
        }
        else if(logType == 3){
            return getOptionLog(pageIndex);
        }
        return new ArrayList<>();
    }

    public static List<ExceptionData> getErrLog(int pageIndex){
        List<ExceptionLogEntity> lsFind =   LitePal.order("logNumber DESC").offset(pageIndex * 14).limit(14).find(ExceptionLogEntity.class);


        List<ExceptionData> ls = new ArrayList<>();
        for(ExceptionLogEntity item : lsFind){
            ExceptionData data = new ExceptionData(item.getLogNumber(),item.getLogTime(),item.getLogContent());
            ls.add(data);
        }


        return ls;
    }

    public static List<ExceptionData> getSwitchLog(int pageIndex){
       // Log.d("SHOOTEE_SWITCH","进来了：：getSwitchLog");
        List<SwitchLogEntity> lsFind =   LitePal.order("logNumber DESC").offset(pageIndex * 14).limit(14).find(SwitchLogEntity.class);


        List<ExceptionData> ls = new ArrayList<>();
        for(SwitchLogEntity item : lsFind){
            ExceptionData data = new ExceptionData(item.getLogNumber(),item.getLogTime(),item.getLogContent());
            ls.add(data);
        }

      //  Log.d("SHOOTEE_SWITCH","找到了：：getSwitchLog"+ls.size());
        return ls;
    }

    public static List<ExceptionData> getOptionLog(int pageIndex){

//        long[] ids = new long[14];
//        for(int i = 0;i< 14;i++){
//            ids[i]  =  pageIndex * 14 +(i+1);
//        }

        List<OptionLogEntity> lsFind =   LitePal.order("logNumber DESC").offset(pageIndex * 14).limit(14).find(OptionLogEntity.class);
        List<ExceptionData> ls = new ArrayList<>();
        for(OptionLogEntity item : lsFind){
            ExceptionData data = new ExceptionData(item.getLogNumber(),item.getLogTime(),item.getLogContent());
            ls.add(data);
        }


        return ls;
    }
}
